home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / dragonfl / aaplayr1.pas < prev    next >
Pascal/Delphi Source File  |  1998-05-27  |  21KB  |  726 lines

  1. unit Aaplayr1;
  2.  
  3. { Delphi 2 Demo program for flic panel component }
  4. { 27th May 1998 }
  5.  
  6. { ------------------------------------------------------------------------- }
  7. interface
  8.  
  9. uses
  10.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  11.   Forms, Dialogs, ExtCtrls, StdCtrls, Spin, Menus, Gauges,
  12.   AAPlayr2, MMSystem, FlicPanel;
  13.  
  14. const
  15.    SYSTEM_PATH_LENGTH = 144;
  16.    USER_PATH_LENGTH = 255;
  17.  
  18. type
  19.   TForm1 = class(TForm)
  20.     MainMenu1: TMainMenu;
  21.     File1: TMenuItem;
  22.     Open1: TMenuItem;
  23.     Exit1: TMenuItem;
  24.     OpenDialog1: TOpenDialog;
  25.     Gauge1: TGauge;
  26.     Bevel3: TBevel;
  27.     OpenDialog2: TOpenDialog;
  28.     LoopPlay: TMenuItem;
  29.     N3: TMenuItem;
  30.     Exitprogram1: TMenuItem;
  31.     AnimGroupBox: TGroupBox;
  32.     Label3: TLabel;
  33.     WidthValue: TEdit;
  34.     HeightValue: TEdit;
  35.     FramesLabel: TLabel;
  36.     FramesValue: TEdit;
  37.     SpeedValue: TEdit;
  38.     Anim2GroupBox: TGroupBox;
  39.     Label5: TLabel;
  40.     SpeedEdit: TSpinEdit;
  41.     XEdit: TEdit;
  42.     YEdit: TEdit;
  43.     Label6: TLabel;
  44.     FramePanel: TPanel;
  45.     LoopPanel: TPanel;
  46.     Label4: TLabel;
  47.     NotifyGroupBox: TGroupBox;
  48.     CheckBox1: TCheckBox;
  49.     CheckBox2: TCheckBox;
  50.     CheckBox3: TCheckBox;
  51.     CheckBox4: TCheckBox;
  52.     CheckBox5: TCheckBox;
  53.     CheckBox6: TCheckBox;
  54.     CheckBox7: TCheckBox;
  55.     CheckBox8: TCheckBox;
  56.     CheckBox9: TCheckBox;
  57.     CheckBox10: TCheckBox;
  58.     OpenDialog3: TOpenDialog;
  59.     NotifyCancelButton: TButton;
  60.     Sound1: TMenuItem;
  61.     Associate1: TMenuItem;
  62.     ButtonPanel: TPanel;
  63.     Button1: TButton;
  64.     Button2: TButton;
  65.     Button3: TButton;
  66.     Button4: TButton;
  67.     Button5: TButton;
  68.     Button6: TButton;
  69.     Button7: TButton;
  70.     Button8: TButton;
  71.     procedure FormCreate(Sender: TObject);
  72.     procedure FormDestroy(Sender: TObject);
  73.     procedure SpeedEditChange(Sender: TObject);
  74.     procedure OpenFlicFile(AFilename: string);
  75.     procedure Open1Click(Sender: TObject);
  76.     procedure XEditChange(Sender: TObject);
  77.     procedure YEditChange(Sender: TObject);
  78.     procedure Associate1Click(Sender: TObject);
  79.     procedure NotifyCheckBoxClick(Sender: TObject);
  80.     procedure LoopPlayClick(Sender: TObject);
  81.     procedure NotifyCancelButtonClick(Sender: TObject);
  82.     procedure Exitprogram1Click(Sender: TObject);
  83.     procedure Help2Click(Sender: TObject);
  84.     procedure Button1Click(Sender: TObject);
  85.     procedure Button2Click(Sender: TObject);
  86.     procedure Button3Click(Sender: TObject);
  87.     procedure Button4Click(Sender: TObject);
  88.     procedure Button5Click(Sender: TObject);
  89.     procedure Button6Click(Sender: TObject);
  90.     procedure Button7Click(Sender: TObject);
  91.     procedure Button8Click(Sender: TObject);
  92.   private
  93.     { Private declarations }
  94.     SoundLoops: integer;
  95.     SoundPtrs: array[1..10] of PChar;
  96.     SoundFlags: array[1..10] of Boolean;
  97.   public
  98.     { Public declarations }
  99.    protected
  100.     { Protected declarations }
  101.     procedure WndProc(var Message: TMessage); override;
  102.   end;
  103.  
  104. var
  105.   Form1: TForm1;
  106.   { The following two are needed because trying to access the message
  107.       numbers in the flic panel component in a form's WndProc
  108.       causes a GPF when WndProc is called during form (and hence
  109.       flic panel) creation: }
  110.    NotifyMessageNum: word;
  111.    StopMessageNum: word;
  112.    FrameMessageNum: word;
  113.    RedimMessageNum: word;
  114.  
  115. { ------------------------------------------------------------------------- }
  116. implementation
  117.  
  118. {$R *.DFM}
  119.  
  120. { ------------------------------------------------------------------------- }
  121. procedure TForm1.FormCreate(Sender: TObject);
  122.  
  123. var
  124.    tempp: integer;
  125.  
  126. begin
  127.  
  128.    for tempp := 1 to 10 do
  129.       begin
  130.       GetMem(SoundPtrs[tempp], SYSTEM_PATH_LENGTH);
  131.       end;
  132.  
  133.    for tempp := 1 to 10 do
  134.       begin
  135.       SoundFlags[tempp] := FALSE;
  136.       end;
  137.  
  138. end;
  139.  
  140. { ------------------------------------------------------------------------- }
  141. procedure TForm1.FormDestroy(Sender: TObject);
  142.  
  143. var
  144.    tempp: integer;
  145.  
  146. begin
  147.  
  148.    for tempp := 1 to 10 do
  149.       begin
  150.       FreeMem(SoundPtrs[tempp], SYSTEM_PATH_LENGTH);
  151.       end;
  152.  
  153. end;
  154.  
  155. { ------------------------------------------------------------------------- }
  156. procedure TForm1.Open1Click(Sender: TObject);
  157.  
  158. begin
  159.  
  160.    if OpenDialog1.Execute then
  161.       begin
  162.       OpenFlicFile(OpenDialog1.Filename);
  163.       Open1.enabled := FALSE;
  164.       end;
  165.  
  166. end;
  167.  
  168. { ------------------------------------------------------------------------- }
  169. procedure TForm1.OpenFlicFile(AFilename: string);
  170.  
  171. var
  172.    tempstr: string[12];
  173.  
  174. begin
  175.    form2.Enabled := TRUE;
  176.    form2.visible := TRUE;
  177.    { If these are in Form1's constructor, causes GPF }
  178.    NotifyMessageNum := form2.flicpanel1.NotifyMessageNum;
  179.    StopMessageNum := form2.flicpanel1.StopMessageNum;
  180.    FrameMessageNum := form2.flicpanel1.FrameMessageNum;
  181.    RedimMessageNum := form2.flicpanel1.RedimMessageNum;
  182.  
  183.    with form2.flicpanel1 do
  184.       begin
  185.       FileName := AFileName;
  186.       CallbackHandle := Form1.handle;
  187. //      Stretchable := TRUE;
  188.       Open;
  189.       str(FlicWidth, tempstr);
  190.       WidthValue.Text := tempstr;
  191.       str(FlicHeight, tempstr);
  192.       HeightValue.Text := tempstr;
  193.       str(FlicFrames, tempstr);
  194.       FramesValue.Text := tempstr;
  195.       str(DesignSpeed, tempstr);
  196.       SpeedValue.Text := tempstr;
  197.       SpeedEdit.Value := Speed;
  198.       SpeedEdit.Enabled := TRUE;
  199.       XEdit.Enabled := TRUE;
  200.       YEdit.Enabled := TRUE;
  201.       Gauge1.progress := 1;
  202.       FramePanel.Caption := '1';
  203.       LoopPanel.Caption := '1';
  204.       Gauge1.maxvalue := FlicFrames;
  205.       Associate1.enabled := TRUE;
  206.       LoopPlay.Enabled := TRUE;           { turn on play looping menu }
  207.       X := 4;                             { to let the panel border show }
  208.       Y := 4;
  209.       PlayLoops := 0;                     { play animation once }
  210.       PlayFrames := FlicFrames;
  211.       end;
  212.  
  213. //   form2.flicpanel1.width := form2.flicpanel1.flicwidth * 2;
  214. //   form2.flicpanel1.paint;
  215.    form2.Width := form2.flicpanel1.Width + 16;
  216.    form2.Height := form2.flicpanel1.Height + 33;
  217.    form2.Caption := ExtractFilename(AFilename);
  218.    CheckBox1.Enabled := TRUE;
  219.    CheckBox2.Enabled := TRUE;
  220.    CheckBox3.Enabled := TRUE;
  221.    CheckBox4.Enabled := TRUE;
  222.    CheckBox5.Enabled := TRUE;
  223.    CheckBox6.Enabled := TRUE;
  224.    CheckBox7.Enabled := TRUE;
  225.    CheckBox8.Enabled := TRUE;
  226.    CheckBox9.Enabled := TRUE;
  227.    CheckBox10.Enabled := TRUE;
  228.    Associate1.Enabled := TRUE;      { turn on sound association button }
  229. end;
  230.  
  231. { ------------------------------------------------------------------------- }
  232. procedure TForm1.SpeedEditChange(Sender: TObject);
  233.  
  234. begin
  235.    form2.flicpanel1.Speed := SpeedEdit.Value;
  236. end;
  237.  
  238.  
  239. { ------------------------------------------------------------------------- }
  240. procedure TForm1.Associate1Click(Sender: TObject);
  241.  
  242. begin
  243.  
  244.    if OpenDialog2.Execute then
  245.       begin
  246.       form2.flicpanel1.Sound := OpenDialog2.Filename;
  247.       Caption := ExtractFilename(form2.flicpanel1.Filename) + ' + ' +
  248.                                     ExtractFilename(OpenDialog2.Filename);
  249.       end;
  250.  
  251. end;
  252.  
  253.  
  254. { ------------------------------------------------------------------------- }
  255. procedure TForm1.XEditChange(Sender: TObject);
  256.  
  257. var
  258.    temp, temp2: integer;
  259.  
  260. begin
  261.  
  262.    if Sender = XEdit then
  263.       begin
  264.       val(XEdit.Text, temp2, temp);
  265.  
  266.       if (temp = 0) and (temp2 > -1) then
  267.          begin
  268.          form2.flicpanel1.X := temp2;
  269.          end;
  270.  
  271.       end;
  272.  
  273. end;
  274.  
  275. { ------------------------------------------------------------------------- }
  276. procedure TForm1.YEditChange(Sender: TObject);
  277.  
  278. var
  279.    temp, temp2: integer;
  280.  
  281. begin
  282.  
  283.    if Sender = YEdit then
  284.       begin
  285.       val(YEdit.Text, temp2, temp);
  286.  
  287.       if (temp = 0) and (temp2 > -1) then
  288.          begin
  289.          form2.flicpanel1.Y := temp2;
  290.          end;
  291.  
  292.       end;
  293.  
  294. end;
  295.  
  296.  
  297. { ------------------------------------------------------------------------- }
  298. procedure TForm1.NotifyCheckBoxClick(Sender: TObject);
  299.  
  300. var
  301.    temp, temp2: integer;
  302.  
  303. begin
  304.    val(TCheckBox(Sender).Caption, temp2, tem